package com.newblog.test;

import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class AutoRun {
	private static String fields="" ;
	private static String methods="";
	private static String toUpper(String s){
		 return s.substring(0, 1).toUpperCase()+s.substring(1);
	}

	public static void writeFiled(Types t){
		String field="\t"+"private"+" "+t.getType()+ " "+t.getField()+";\r\n";
		fields +=field;
		
	}
	public static void main(String[] args){
		List l = new LinkedList();
		Types t = new Types("int","name");
		l.add(t);
	    run(l);
	}
	public static void writeSet(Types t){
		String setMethod ="\t"+"public"+" "+"void"+" " +"set"+toUpper(t.getField())+"("+t.getType()+" "+t.getField()+"){\r\n";
		setMethod+="\t\tthis."+t.getField()+"="+t.getField()+";"+"\r\n";
		setMethod+="\t}\r\n";	
		methods+=setMethod;
	}
	public static void writeGet(Types t){
		String getMethod ="\t"+"public"+" "+"void"+" " +"get"+toUpper(t.getField())+"(){\r\n";
		getMethod+="\t\t return this."+t.getField()+";"+"\r\n";
		getMethod+="\t}\r\n";	
		methods+=getMethod;
	}
	public static void save(){
		try{
		  Writer writer = new FileWriter("src/com/newblog//test/test.java");
		  writer.write(fields);
		  writer.write(methods);
		  writer.close();
		}
		catch(IOException e){
			e.printStackTrace();
		}
	}
	public static void run(List l){
		Iterator iter = l.iterator();
		while(iter.hasNext()){
		    Types t = 	(Types)iter.next();
		    writeFiled(t);
		    writeGet(t);
		    writeSet(t);
    	}
		save();
	}

}
